package com.jmcgg.freesky.common.db;

import java.io.Serializable;
import java.sql.DriverManager;

import org.apache.log4j.Logger;

/**
 * Title: FreeSky Common Java Library <br>
 * Description: FreeSky Common Java Library <br>
 * Copyright: Copyright (c) 2005~2009 www.afss.cn <br>
 * Company: Amei's FreeSky Studio <br>
 * 
 * @author <b>Jacky Chou</b> (AFSS [Amei's FreeSky Studio])
 * @version 1.2.0, 2008-02-23, Upgrade freesky.jar to 1.2.0 with Struts 2
 * @version 1.0.0, 2006-05-30, Initial Version
 */
public class DBAccessBean extends DBConnBean implements Serializable {

	private static final long serialVersionUID = 4238286174543073155L;
	/**
	 * Log4J Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(DBAccessBean.class);
	// MDB file name(path)
	public static String FS_MDB_PATH = "freesky.mdb";

	public DBAccessBean() {
		super();
	}

	/**
	 * ��������MDB�ļ���·��������ݿ�
	 * 
	 * @param filePath
	 *            MDB�ļ�·��
	 */
	public DBAccessBean(String odbcName) {
		this.getConnection(odbcName);
	}

	public void getConnection() {
		try {
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
			conn = DriverManager.getConnection(
					"jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};"
							+ "DBQ=" + FS_MDB_PATH, "admin", "");
		} catch (java.lang.ClassNotFoundException ce) {
			logger.error("Get Connection error:", ce);
		} catch (java.sql.SQLException se) {
			logger.error("Get Connection error:", se);
		} catch (Exception e) {
			logger.error("Get Connection error:", e);
		}
	}

	/**
	 * ͨ��ODBC�õ����ӡ������޲����췽�����ٵ��ô˷���������ݿ�����
	 */
	public void getConnection(String odbcName) {
		try {
			// load the jdbc driver ;
			Class.forName("sun.jdbc.odbc.jdbcodbcdriver").newInstance();
			conn = DriverManager.getConnection("jdbc:odbc:" + odbcName);
		} catch (java.lang.ClassNotFoundException ce) {
			logger.error("Get Connection error:", ce);
		} catch (java.sql.SQLException se) {
			logger.error("Get Connection error:", se);
		} catch (Exception e) {
			logger.error("Get Connection error:", e);
		}
	}
}
